package com.wn.manpower.web;

import com.wn.common.PageBean;
import com.wn.common.ResponseEntity;
import com.wn.entity.Hr;
import com.wn.manpower.service.HumanResourcesService;
import com.wn.manpower.vo.HumanResourcesVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 人力资源调用
 * @author dzj
 * date: 2022/10/20
 */
@Slf4j
@RestController
@RequestMapping("/manpower")
public class HumanResourcesController {

    @Autowired
    HumanResourcesService humanResourcesService;

    @RequestMapping("/add")
    public ResponseEntity add(@RequestBody Hr hr) {
        log.debug("---------------------hr:{}", hr);
        humanResourcesService.add(hr);
        return ResponseEntity.success;
    }

    @RequestMapping("/update")
    public ResponseEntity update(@RequestBody Hr hr) {
        humanResourcesService.update(hr);
        return ResponseEntity.success;
    }

    @RequestMapping("/del/{id}")
    public ResponseEntity del(@PathVariable int id) {
        Hr hr = new Hr();
        hr.setId(id);
        hr.setState("n");
        humanResourcesService.update(hr);
        return ResponseEntity.success;
    }

    @RequestMapping("/getById/{id}")
    public ResponseEntity getById(@PathVariable int id) {
        Hr hr = humanResourcesService.getById(id);
        return new ResponseEntity(hr);
    }

    @RequestMapping("/getPageByCondition")
    public ResponseEntity getByCondition(@RequestBody HumanResourcesVo humanResourcesVo) {
        log.debug("humanResourcesVo:{}", humanResourcesVo);
        PageBean<Hr> pageBean = humanResourcesService.getPageByCondition(humanResourcesVo.getHr(), humanResourcesVo.getCurrPage(), humanResourcesVo.getPageSize());
        return new ResponseEntity(pageBean);
    }
}
